Dashboard.addWidget({ getId : function(){ return "cartesian-charts-widget"; }, getName : function(){ return "Cartesian Charts"; }, getDescription : function(){ return { en : 'Widget that display one or more KPIs in a chart', de : 'Widget that display one or more KPIs in a chart' }; }, getIconClass : function(){ return 'glyphicon glyphicon-signal'; }, createContent : function(configuration, currentWidgetInstanceId){ var chartType = configuration.chartType.value; var modelId = configuration.modelId.value; var kpiId = configuration.kpiId.value; var kpiFieldForAxisX = configuration.kpiFieldForAxisX.value; var kpiFieldForAxisY = configuration.kpiFieldForAxisY.value; var kpiMoreInfoForThreshold = configuration.kpiMoreInfoForThreshold.value; var kpiMoreInfoForAlert = configuration.kpiMoreInfoForAlert.value; var kpiInfo = ModelManager.getKpiInfo(modelId, kpiId); var kpiMeasure = Dashboard.evaluateKpi(currentWidgetInstanceId, modelId, kpiId); if(kpiFieldForAxisX!='' && !kpiMeasure.columns.includes(kpiFieldForAxisX)) throw 'Invalid field for the X Axis provided: ' + kpiFieldForAxisX; if(!kpiMeasure.columns.includes(kpiFieldForAxisY)) throw 'Invalid field for the Y Axis provided: ' + kpiFieldForAxisY; var xData = []; var yData = []; kpiMeasure.data.forEach(function(item, index){ xData.push(kpiFieldForAxisX!=''?item[kpiFieldForAxisX]:index); yData.push(item[kpiFieldForAxisY]); }); xData.reverse(); var xDataUnit = kpiFieldForAxisX!=''?kpiInfo.getFieldInfos(kpiFieldForAxisX).measureUnit:'Counter'; var yDataUnit = kpiInfo.getFieldInfos(kpiFieldForAxisY).measureUnit; var thresholdNum = kpiInfo.moreInfo[kpiMoreInfoForThreshold]; var alertNum = kpiInfo.moreInfo[kpiMoreInfoForAlert]; var chartScales = {}; if(chartType!='radar'){ chartScales = { xAxes: [{ display: true, scaleLabel: { display: true, labelString: xDataUnit }, ticks: { suggestedMin: 0 } }], yAxes: [{ display: true, scaleLabel: { display: true, labelString: yDataUnit }, ticks: { suggestedMin: 0 } }] }; } var annotations = []; if(thresholdNum!=''){ annotations.push({ type: 'line', mode: chartType=='horizontalBar'?'vertical':'horizontal', scaleID: chartType=='horizontalBar'?'x-axis-0':'y-axis-0', value: thresholdNum, borderColor: 'red', borderWidth: 2, label: { backgroundColor: 'red', content: 'Threshold: '+thresholdNum, position: 'right', enabled: true } }); } if(alertNum!=''){ annotations.push({ type: 'line', mode: chartType=='horizontalBar'?'vertical':'horizontal', scaleID: chartType=='horizontalBar'?'x-axis-0':'y-axis-0', value: alertNum, borderColor: 'rgb(255, 182, 0)', borderWidth: 2, label: { backgroundColor: 'rgb(255, 182, 0)', content: 'Alert: '+alertNum, position: 'right', enabled: true } }); } var options = { responsive: true, tooltips: { mode: 'index', intersect: false, }, hover: { mode: 'nearest', intersect: true }, scales: chartScales, pan: { enabled: true, mode: 'xy' }, zoom: { enabled: true, mode: 'xy' }, annotation: { annotations: annotations } }; if(chartType=='radar'){ delete options.scales; options.scale = { ticks: { suggestedMin: 0 } } } var canvas = $(''); var chart = new Chart(canvas, { type: chartType!='curve'?chartType:'line', data: { labels: xData, datasets: function(){ var param = { label: kpiInfo.name, backgroundColor : 'rgb(54, 162, 235, 0.4)', borderColor : 'rgb(54, 162, 235)', borderWidth: 1, fill: true, data: yData }; if(chartType=='line') param.lineTension=0; return[param]; }() }, options: options }); return canvas; }, getConfiguration : function(){ return { chartType : { description : { en : '', de : '' }, value : '' }, modelId : { description : { en : '', de : '' }, value : '' }, kpiId : { description : { en : '', de : '' }, value : '' }, kpiFieldForAxisX : { description : { en : '', de : '' }, value : '' }, kpiFieldForAxisY : { description : { en : '', de : '' }, value : '' }, kpiMoreInfoForThreshold : { description : { en : '', de : '' }, value : '' }, kpiMoreInfoForAlert : { description : { en : '', de : '' }, value : '' } }; }, createConfiguration : function(presetConfig){ var VIEW = { chartTypeSelect : $('') .append(function(){ var modelSelectArray = [ '' ]; ModelManager.getKpiModelList().forEach(function(item){ modelSelectArray.push(''); }, this); return modelSelectArray; }()) .change(function(){ var modelId = VIEW.modelSelect.find(":selected").val(); VIEW.kpiSelect.empty(); VIEW.kpiSelect.append(''); if(modelId != '') ModelManager.getKpiList(modelId).forEach(function(item){ VIEW.kpiSelect.append(''); }, this); VIEW.kpiSelect.trigger("change"); }), kpiSelect : $('').append(''), kpiFieldsForYSelect : $('').append(''), kpiMoreInfoForAlertSelect : $('